/**
 * SystemPreferences.cpp
 */

#include <fstream>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>

#include "SystemPreferences.h"

SystemPreferences::SystemPreferences() :
  _xRes(1280), _yRes(1024), _depthColor(16), _velocity(500),
      _backTranslate(3.0), _lateralBackTranslate(5.0), _lateralDelta(1.3),
      _lateralRotate(45.0) {
}

SystemPreferences* SystemPreferences::SystemPreferencesFactory(std::string file) {
  SystemPreferences* sp = new SystemPreferences();
  {
    std::ifstream ifs(file.c_str());
    boost::archive::text_iarchive ia(ifs);
    ia >> sp;
  }
  return sp;
}

SystemPreferences::SystemPreferences(int xRes, int yRes, int depthColor,
    int velocity, float backTranslate, float lateralBackTranslate,
    float lateralDelta, float lateralRotate) :
  _xRes(xRes), _yRes(yRes), _depthColor(depthColor), _velocity(velocity),
      _backTranslate(backTranslate),
      _lateralBackTranslate(lateralBackTranslate), _lateralDelta(lateralDelta),
      _lateralRotate(lateralRotate) {
}

SystemPreferences::~SystemPreferences() {

}

void SystemPreferences::setScreenResolution(int width, int height, int depth) {
  _xRes = width;
  _yRes = height;
  _depthColor = depth;
}

void SystemPreferences::getScreenResolution(int& width, int& height, int& depth) {
  width = _xRes;
  height = _yRes;
  depth = _depthColor;
}

float SystemPreferences::transition(float t) {
  return t;
}

void SystemPreferences::saveConfiguration(std::string file) {
  std::ofstream outFile(file.c_str());
  {
    boost::archive::text_oarchive outArchive(outFile);
    outArchive << this;
  }
}

int SystemPreferences::getXRes() {
  return _xRes;
}

int SystemPreferences::getYRes() {
  return _yRes;
}

int SystemPreferences::getDepthColor() {
  return _depthColor;
}

int SystemPreferences::getVelocity() {
  return _velocity;
}

float SystemPreferences::getBackTranslate() {
  return _backTranslate;
}

float SystemPreferences::getLateralBackTranslate() {
  return _lateralBackTranslate;
}

float SystemPreferences::getLateralDelta() {
  return _lateralDelta;
}

float SystemPreferences::getLateralRotate() {
  return _lateralRotate;
}

template<class Archive>
void SystemPreferences::serialize(Archive & ar, const unsigned int version) {
  ar & _xRes;
  ar & _yRes;
  ar & _depthColor;
  ar & _velocity;
  ar & _backTranslate;
  ar & _lateralBackTranslate;
  ar & _lateralDelta;
  ar & _lateralRotate;
}
